#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int w[maxn], sum, n;
int dp[maxn];
vector<int> g[maxn];
void addedge(int f, int t) { g[f].push_back(t), g[t].push_back(f); }
void dfs(int fa, int no)
{
    int mx = 0;
    for (int i = 0; i < g[no].size(); ++i)
    {
        if (fa == g[no][i])
            continue;
        dfs(no, g[no][i]);
        mx = max(mx, dp[g[no][i]]);
    }
    dp[no] = mx + w[no];
}
int main()
{
    int c = 10;
    string name = "kZimeAndGit";
    for (int c = 1; c <= 10; ++c)
    {
        string in = name + to_string(c) + ".in", out = name + to_string(c) + ".ans";
        freopen(in.c_str(), "r", stdin);
        freopen(out.c_str(), "w", stdout);
        memset(dp, 0, sizeof(dp));
        memset(w, 0, sizeof(w));
        sum = 0;
        for (int i = 0; i < maxn; ++i) g[i].clear();
        ios::sync_with_stdio(0);
        cin.tie(0);
        cin >> n;
        for (int i = 1; i < n; ++i)
        {
            int f, t, v;
            cin >> f >> t >> v;
            w[t] = v;
            addedge(f, t);
            sum += w[t];
        }
        dfs(0, 1);
        cout << sum - dp[1] << endl;
    }

}